﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.Text;
using TouchUI;

namespace MobileStore.WinPhone
{
    public class DetailDialog : Dialog
    {
        private DetailScrollPanel detailScrollPanel;
        private int headerHeight;
        private Car car;

        public DetailDialog(int screenFactor, Rectangle r, Car car)
        {
            Text = car.Model;
            if(Common.Values.TouchDevice)
                headerHeight = 24 * screenFactor;
            ScreenFactor = screenFactor;
            Rectangle = r;
            this.car = car;
            //CommonDomain commonDomain = new CommonDomain();
            //Car car = commonDomain.GetCars().First();
            detailScrollPanel = new DetailScrollPanel(car, ScreenFactor,  new Rectangle(0, headerHeight, r.Width, r.Height - headerHeight));
            HasScrollControl = true;
        }

        public override void Paint(Graphics g)
        {
            g.Clear(BackColor);
            detailScrollPanel.Paint(g);
            if(headerHeight > 0)
            {
                g.FillRectangle(Common.Values.BackBrush, 0, 0, Rectangle.Width, headerHeight);
                g.DrawString(Text, Common.Values.Font, Common.Values.HighBrush, 8 * ScreenFactor, 5 * ScreenFactor);
                g.DrawLine(Common.Values.Pen, 0, headerHeight - 1, Rectangle.Width, headerHeight - 1);
            }
        }

        public override void MouseDown(Point p)
        {
            detailScrollPanel.MouseDown(new Point(p.X, p.Y - headerHeight));
        }

        public override void MouseMove(Point p)
        {
            detailScrollPanel.MouseMove(new Point(p.X, p.Y - headerHeight));
        }

        public override void MouseUp(Point p)
        {
            detailScrollPanel.MouseUp(new Point(p.X, p.Y - headerHeight));
        }

        public override void KeyDown(KeyEventArgs e)
        {
            detailScrollPanel.KeyDown(e);
        }

        public override void KeyUp(KeyEventArgs e)
        {
            detailScrollPanel.KeyUp(e);
        }

        public override void Resize(Rectangle r)
        {
            this.Rectangle = r;
            detailScrollPanel.Rectangle = new Rectangle(0, headerHeight, r.Width, r.Height - headerHeight);
        }

        public override void DoAutomaticMotion()
        {
            detailScrollPanel.DoAutomaticMotion();
        }
    }
}
